home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / lists / mint / l_0799 / 521 < prev    next >
Encoding:
Internet Message Format  |  1994-08-27  |  2.3 KB

  1. From: inf2gr04@informatik.uni-frankfurt.de
  2. Posted-Date: Wed, 6 Oct 93 8:38:48 MEZ
  3. Received-Date: Wed, 6 Oct 93 08:38:48 +0100
  4. Message-Id: <9310060738.AA22203@hptest.rbi.informatik.uni-frankfurt.de>
  5. Subject: Re: sleep() and device drivers ...
  6. To: mint@atari.archive.umich.edu
  7. Date: Wed, 6 Oct 93 8:38:48 MEZ
  8. Mailer: Elm [revision: 70.85]
  9.  
  10.  
  11. Not long ago I asked for a metod for device driver functions to decide,
  12. whether sleep() was interrupted by a signal or not.
  13.  
  14. Finally I got a solution myself.
  15.  
  16. The underlying question of the above is to decide, if a signal handler could
  17. have called the device's close() function thus kfree()ing an object the
  18. sleep()ing function is just operating on.
  19.  
  20. To decide this we use a counter `intr' which is incremented every time the 
  21. device drivers close() is called and an object is really freed
  22. (if  fileptr->links <= 0):
  23.  
  24. unsigned long intr = 0;
  25.  
  26. long
  27. dev_close (fp, pid)
  28.     FILEPTR *fp;
  29.     short pid;
  30. {
  31.  
  32.     ...
  33.  
  34.     if (fp->links <= 0) {
  35.         ++intr;
  36.         /* free the data associated with the fileptr */
  37.     }
  38.  
  39.     ...
  40.  
  41.     return 0;
  42. }
  43.  
  44. Furthermore we use a new sleep() function, which looks like this:
  45.  
  46. short
  47. isleep (queue, cond)
  48.     short queue;
  49.     long cond;
  50. {
  51.     unsinged long ointr = intr;
  52.     sleep (queue, cond);
  53.     return (ointr != intr);
  54. }
  55.  
  56. Isleep() will return true if there were any 'disposing' calls to
  57. dev_close() while sleep()ing in a device drivers function.
  58. If isleep() returns true, the function calling isleep() should
  59. not touch any objects that could be freed by calls to dev_close() and
  60. perhaps return whatever is equivalent to EINTR or ERESTARTSYS. Like this:
  61.  
  62. long
  63. dev_read (fp, buf, buflen)
  64.     FILEPTR *fp;
  65.     char *buf;
  66.     long buflen;
  67. {
  68.     while (data not available) {
  69.         if (isleep (IO_Q, (long)fp->devinfo)) {
  70.             /* perhaps fp was freed, so we cannot
  71.                reference it to see if data is available */
  72.             return ERESTARTSYS;
  73.         }
  74.     }
  75.     
  76.     read the data into `buf';
  77.     ...
  78. }
  79.  
  80. I strongly suggest to change pipefs' device driver and all other devices
  81. drivers which tend to have the same problem in the described way, in order
  82. to avoid references to already freed memory.
  83.  
  84. Perhaps we should implement ERESTARTSYS in the kernel. If a device
  85. driver function returnes this error code, the kernel should restart the
  86. system call, checking again the filedescriptors, etc. If they are still
  87. valid, perhaps the call can be completed this time without interrupts.
  88.  
  89. Comments appreciated,
  90.  
  91. -- Kay Roemer.
  92.  
  93.